package cn.quartz.simple;

import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class CronTriggerExample {
	
	public void run() throws Exception{
		String corn = "0/1 * * * * ?";
		
		SchedulerFactory sf = new StdSchedulerFactory();
	    Scheduler sched = sf.getScheduler();
	    
	    JobDetail job = JobBuilder.newJob(SimpleJob.class).withIdentity("job1", "group1").build();
	    
	    CronTrigger trigger = (CronTrigger)TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").withSchedule(CronScheduleBuilder.cronSchedule(corn)).build();
	    
	    Date date = sched.scheduleJob(job, trigger);
	    
	    System.out.println(job.getKey() + " has been scheduled to run at: " + date + " and repeat based on expression: " + trigger.getCronExpression());
	    
	    sched.start();
	    
	    
	}
	
	public static void main(String[] args) throws Exception {
		
		CronTriggerExample example = new CronTriggerExample();
	    example.run();
	}

}
